<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<title>管理员后台</title>
		<link rel="stylesheet" type="text/css" th:href="@{/css/cart.css}" />
		<link rel="stylesheet" type="text/css" th:href="@{/dist/css/bootstrap.min.css}">
		<link rel="stylesheet" type="text/css" th:href="@{/css/index.css}"/>
		<link rel="stylesheet" type="text/css" th:href="@{/css/animate.css}"/>
		<link rel="stylesheet" th:href="@{/layui/css/layui.css}">

	</head>

	<body>
    <!--导航部分  begin-->
    <div th:replace="admin/common/header :: nav"></div>
    <!--导航部分 end-->

		<!--购物车 begin-->
		<!--外层div-->

<!--		<div id="allUsersData"></div>-->
	<div class="container">
		<!--左边-->
		<div class="col-md-8 col-sm-12" style="width:100%">
			<!--左边-->
			<ol class="breadcrumb">
				<li>
					<a href="#" class="text-success"><span class="glyphicon glyphicon-heart"></span>&nbsp;&nbsp;申诉管理</a>
				</li>
			</ol>

			<!--购物车表格 begin-->
			<div class="table-responsive" id="imgDiv">
				<table class="table table-hover table-striped" style="vertical-align:middle;" >
					<thead>
					<tr class="text-success success">
						<th style="width: 30px;">
<!--							<input type="checkbox" id="selectAll" onclick="selectAll(this)">-->
							<!--								<input type="checkbox" id="testId" onclick="selectAll(this)">-->
						</th>
						<th id="sequence">序号</th>
						<th>用户名</th>
						<th>申诉时间</th>
						<th>封禁原因</th>
						<th>申诉理由</th>
						<th>状态</th>
						<th >操作</th>
					</tr>
					</thead>
					<tbody id="tby" th:each="appeal:${appealList}" >
					<tr>
						<td style="width: 30px;">
<!--							<input type="checkbox" name="cks"  th:value="${appeal.id}" >-->
							<!--								<input type="checkbox" name="cks" onclick="cks(this)" name="testName" value="${item.id}">-->
						</td>
						<td th:text="${appeal.id}"></td>
						<td th:text="${appeal.username}"></td>

						<td th:text="${#calendars.format(appeal.createDate,'yyyy-MM-dd HH:mm:ss')}"></td>
						<td th:text="${appeal.forbidReason}"></td>
						<td>
							<button class="btn btn-info" th:onclick="displayInfo([[${appeal.appealReason}]])">预览</button>
						</td>
						<td th:if="${appeal.state ==1}">待审核</td>
						<td th:if="${appeal.state==2}"><font color="#5cb85c">审核通过</font></td>
						<td th:if="${appeal.state==3}"><font color="red">审核未通过</font></td>
						<td th:if="${appeal.state ==1}">
							<a class="btn btn-success" th:onclick="approve([[${appeal.userId}]],[[${appeal.id}]])">通过</a>
							<a class="btn btn-danger" th:onclick="disapprove([[${appeal.userId}]],[[${appeal.id}]])">不通过</a>
						</td>
						<td th:if="${appeal.state !=1}">
							<a class="btn btn-default" th:href="@{/admin/deleteAppeal(appealId=${appeal.id})}">删除记录</a>
						</td>
					</tr>

					</tbody>
					<tfoot>
					<tr>
						<td colspan="3"></td>
						<td class="text-success">总数量:</td>
						<td class="text-success" th:text="${appealList.size()}"></td>
					</tr>
					<tr style="background-color: white;">

<!--						<td><button class="btn btn-success" data-toggle="modal" data-target="#myModal" th:onclick="deleteUsers()">批量封号</button></td>-->
						<td colspan="4"></td>
						<!--							<td>
                                                        <a href="confirm_order.html" class="btn btn-warning">结算商品</a>
                                                    </td>-->
					</tr>
					</tfoot>
				</table>
			</div>
			<!--购物车 end-->

		</div>

		<!--分页begin-->

		<!--分页end-->
	</div>
		<div class="container">
			<!--首页底部信息 begin-->
			<div th:replace="common/footer :: footer"></div>
		</div>
		<!--end-->

		<!--引入js文件-->
		<script src="js/details.js" th:src="@{/js/details.js}" type="text/javascript" charset="utf-8"></script>
		<script src="js/cart.js" th:src="@{/js/cart.js}" type="text/javascript" charset="utf-8"></script>
		<script src="dist/js/jquery.min.js" th:src="@{/dist/js/jquery.min.js}"></script>
		<script src="js/carousel.js" th:src="@{/js/carousel.js}" type="text/javascript" charset="utf-8"></script>
		<script src="dist/js/bootstrap.min.js" th:src="@{/dist/js/bootstrap.min.js}"></script>
		<script src="js/wow.js" th:src="@{/js/wow.js}"></script>
		<script th:src="@{/layui/layui.js}"></script>
		<script th:inline="javascript">
			//获取应用路径
			var contextPath = [[${#request.getContextPath()}]];
			var pages = [[${pages}]];
			var admin = [[${session.admin}]]

		</script>

		<script type="text/javascript">
			$(function () {
				if (admin == null || admin == undefined || admin == 'undefined') {
					location.href = contextPath + "/book/index";
				}
			})
			if(!(/msie [6|7|8|9]/i.test(navigator.userAgent))) {
				new WOW().init();
			};

		</script>

	<style type="text/css">
		td {text-align: center}
		th {text-align: center}
	</style>
	</body>
	<script>
		//预览申诉理由
		function displayInfo(info) {
			layer.open({
				title: '申诉理由'
				,content: info
				,area: '500px'
			});

		}
		//批量封号
		function deleteUsers(){
			//存储购物记录的id
			var ids = '';
			var thirdModel = document.getElementById("third_del");
			//判断是否选择了商品
			var count = 0;
			//获取所有的checkbox
			var cks = document.getElementsByName("cks");
			//遍历
			for(var i = 0; i < cks.length; i++) {
				if(cks[i].checked) {
					count++;
					ids += cks[i].value + ",";
					// bookIds.add(cks[i].value);
				}
			}
			// var s = new Array();
			// for(var x of bookIds){
			// 	console.log(x)
			// }

			if (ids==''){
				layer.msg('请勾选账号！');
				return;
			}
			layer.confirm('确定封禁？', {
				icon:3,
				btn: ['确定', '取消']
			}, function(index, layero){
				//按钮【按钮一】的回调
				$.ajax({
					url:contextPath + "/admin/deleteUsers",
					data:{"ids":ids},
					type:"post",
					success:function (data) {
						if (data=="success"){
							location.href = contextPath + "/admin/toAllUsers";

						}
						else layer.msg("封号失败")

					}
				})
			}, function(index){
				return ;
			});
		//封号
		}
		//不通过
		function disapprove(userId,appealId) {
			layer.confirm('确定不通过？', {
				icon:3,
				btn: ['确定', '取消']
			}, function(index, layero){
				//按钮【按钮一】的回调
				$.ajax({
					url:contextPath + "/admin/disapprove",
					data:{"userId":userId,"appealId":appealId},
					type:"post",
					success:function (data) {
						if (data=="success"){
							location.href = contextPath + "/admin/toAppealList";
						}
						else layer.msg("操作失败，请重试")
					}
				})
			}, function(index){
				return ;
			});
		}
		//通过
		function approve(userId,appealId) {
			layer.confirm('确定通过？', {
				icon:3,
				btn: ['确定', '取消']
			}, function(index, layero){
				//按钮【按钮一】的回调
				$.ajax({
					url:contextPath + "/admin/approve",
					data:{"userId":userId,"appealId":appealId},
					type:"post",
					success:function (data) {
						if (data=="success"){
							location.href = contextPath + "/admin/toAppealList";
						}
						else layer.msg("操作失败，请重试")
					}
				})
			}, function(index){
				return ;
			});
		}

		//根据用户名搜索
		function searchUsername() {
			var inputUsername = $("#inputUsername").val();
			if (inputUsername != ''){
				window.location.href = contextPath + "/admin/searchUser?inputUsername=" + inputUsername;
			}else layer.msg('请输入用户名！', {icon: 7,anim:6});
		}
	</script>

</html>